package com.arron.myhash;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Classname HashMapTest
 * @Date 2020/9/3 22:34
 * @Created by 刘
 */
public class HashMapTest {

    public static void main(String[] args) {
        Map<String, Object> map =new HashMap<>();
//
        for (int i= 0; i<30;i++){
            map.put(String.valueOf(i),i);
        }
        Map<String, Object> concurrentHashMap =new ConcurrentHashMap<>();



        new Thread(()->{
            for (int i = 0; i < 10000; i++) {
                concurrentHashMap.put(String.valueOf(i),i);
            }

        },"A").start();


        new Thread(()->{
            for (int i = 10000; i < 20000; i++) {
                concurrentHashMap.put(String.valueOf(i),i);
            }

        },"B").start();


        while (Thread.activeCount()>2){
            System.out.println(concurrentHashMap.size());
        }

/**********************测试手写的hashmap***************************************/

//        MyHashMap<String, Object> hashMap = new MyHashMap<String, Object>();
//        for (int i = 0; i < 10; i++) {
//            hashMap.put("刘伟"+i,i);
//        }
//
//        System.out.println(hashMap);
//        System.out.println(hashMap.get("刘伟9"));
        /**
         * 测试在不重写对象的equals方法和hashCode方法的情况
         */
//        HashSet<Person> ps = new HashSet<>();
//        Person liuwe = new Person(1, "liuwe");
//        Person liuwe2 = new Person(1, "liuwe");
//        ps.add(liuwe);
//        ps.add(liuwe2);
//        System.out.println(liuwe.equals(liuwe2));
//
//        System.out.println(liuwe.hashCode() == liuwe2.hashCode());
//
//        System.out.println(ps);

    }

}
